package main

import (
	"fmt"
	"time"
)

func createWorker(id int) chan<- int {
	c := make(chan int)
	go func() {
		for {
			fmt.Printf(" Worker %d received %d\n", id, <-c)
		}
	}()
	return c
}

func worker(id int, c chan int) {
	for {
		n, ok := <-c
		if !ok {
			break
		}
		fmt.Printf(" Worker %d received %d\n", id, n)
	}
}
func workerRange(id int, c chan int) {
	for n := range c {
		fmt.Printf(" Worker %d received %d\n", id, n)
	}
}
func chanDemo() {
	var channels [10]chan<- int
	for i := 0; i < 10; i++ {
		channels[i] = createWorker(i)

	}
	for i := 0; i < 10; i++ {
		channels[i] <- i
	}

	time.Sleep(time.Millisecond)
}

func bufferChannel() {

}
func channelClose() {
	c := make(chan int)
	go workerRange(0, c)
	c <- 'a'
	c <- 'a'
	c <- 'a'
	c <- 'a'
	close(c)
	time.Sleep(time.Millisecond)
}
func main() {
	chanDemo()
	//channelClose()
}
